import js from "@eslint/js";
import globals from "globals";
import tseslint from "typescript-eslint";
import reactPlugin from "eslint-plugin-react";
import prettierPlugin from "eslint-plugin-prettier";
import prettierConfig from "eslint-config-prettier";

export default [

  // 忽略文件
  {
    ignores: ["node_modules/**", "dist/**"]
  },

  // JS 推荐规则
  js.configs.recommended,

  // TS 推荐规则
  ...tseslint.configs.recommended,

  // React 推荐规则（flat）
  {
    ...reactPlugin.configs.flat.recommended,
    settings: {
      react: {
        version: "detect",
        runtime: "automatic" // ⭐ React 17+ 自动 JSX 转换
      }
    }
  },

  // 自定义规则（包含 Prettier 插件）
  {
    files: ["**/*.{js,jsx,ts,tsx}"],
    languageOptions: {
      globals: {
        ...globals.browser,
        ...globals.node,
      }
    },
    plugins: {
      prettier: prettierPlugin,
    },
    rules: {
      "prettier/prettier": "error",
    }
  },

  // 必须放最后：关闭与 Prettier 冲突的 ESLint 规则
  prettierConfig,
];
